package com.yogee.core.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.trello.rxlifecycle.components.support.RxFragment;
import com.umeng.analytics.MobclickAgent;

import butterknife.ButterKnife;

/**
 * Fragment 基类
 *
 * @author BiHaidong
 * @date 2016-12-16
 */
public abstract class BaseFragment extends RxFragment {

    protected View mFragmentView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        if (mFragmentView == null) {
            mFragmentView = inflater.inflate(getLayoutId(), container, false);
            ButterKnife.bind(this, mFragmentView);

        }
        return mFragmentView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }

    /**
     * this Fragment layout res
     * 设置layout布局
     *
     * @return res layout xml id
     */
    protected abstract int getLayoutId();

    /**
     * 页面初始化工作
     */
    protected abstract void initView();
    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(getActivity()); //统计时长
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(getActivity());
    }
}
